/**********************************************
*  Classes:   ParticleSystem
*  Desc:      Abstract class that manages creation,
*			  removal and update of particles. 
*             Inherits from TransformNode
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H

#include "TransformNode.h"

class Particle;

class ParticleSystem : public TransformNode
{
public:

	enum ParticleSystemType
	{
		SYSTEM_FIRE,
		SYSTEM_SMOKE,
		SYSTEM_DEFAULT
	};

	ParticleSystem();
	virtual ~ParticleSystem();

	virtual const NodeType GetType() const
	{
		return NODE_PARTICLESYSTEM;
	}

	virtual ParticleSystemType GetSystemType() const = 0;

	// init system
	virtual void Init(int particlesPerTick,
					  int particleCreationRate,
		              int particleLife,
					  int systemLife)
	{
		m_iParticlesPerTick = particlesPerTick;
		m_iRate = particleCreationRate;
		m_iParticleLife = particleLife;
		m_iSystemLife = systemLife;
	}
	
	// integrates particles
	void MoveParticles(float dt);

	// resets system
	void Reset();

	bool Dead() const
	{
		return m_iSystemLife <= 0;
	}

protected:

	static mth::Vector3 Gravity;
	// rate of particle generation
	int m_iParticlesPerTick;
	// create particles every m_iRate frames
	int m_iRate;
	// max life for particle
	int m_iParticleLife;
	// particle system life
	int m_iSystemLife;

	// Creates particles
	virtual void CreateParticles() = 0;

	virtual void PreUpdate();
	virtual void PostUpdate();
};

SmartPointer(ParticleSystem);

#endif